package com.enhinck.dbutilweb.common.util;

import cn.hutool.core.date.DateUtil;
import lombok.extern.slf4j.Slf4j;

import java.io.File;
import java.util.*;

/**
 * 描述
 *
 * @author huenbin
 * @date 1/15/21 10:24 AM
 */
@Slf4j
public abstract class IFileProcess {
    public abstract String newFolderName();
    public abstract String[] supportExts();

    Map<String, List<File>> groups = new LinkedHashMap<>();

    public Map<String, List<File>> getGroups() {
        return groups;
    }

    public void process(File file) {
        Long lastModified = file.lastModified();
        Date date = new Date(lastModified);
        String key = DateUtil.format(date, "yyyy-MM");
        List<File> group = groups.get(key);
        if (Objects.isNull(group)) {
            group = new ArrayList<>();
            groups.put(key, group);
        }
        group.add(file);
        log.info("处理类{}处理{}文件完成", this.getClass().getSimpleName(), file.getAbsolutePath());
    }

    public boolean support(String ext) {
        for (String docExt : supportExts()) {
            if (docExt.equalsIgnoreCase(ext)) {
                return true;
            }
        }
        return false;
    }
}
